<template>
  <a-select :placeholder="placeholder" v-model="curr" :style="{width:width>0?`${width}px`:'100%'}">
    <a-select-option key="">不限</a-select-option>
    <a-select-option v-for="o in array" :key="o.code">{{ o.name }}</a-select-option>
  </a-select>
</template>

<script>
export default {
  model: {
    prop: 'modelVal', // 指向props的参数名
    event: 'change'// 事件名称
  },
  props: {
    modelVal: {
      type: String,
      default: ''
    },
    width: {
      type: Number,
      default: 0
    },
    placeholder: {
      type: String,
      default: '请选择'
    }
  },
  data () {
    return {
      curr: '',
      array: []
    }
  },
  mounted () {
    this.curr = this.modelVal
    this.search()
  },
  watch: {
    modelVal (newVal) {
      this.curr = newVal
    },
    curr (newVal) {
      this.$emit('change', newVal)
    },
    code () {
      this.search()
    }
  },
  methods: {
    search () {
      this.$http.get('/zg-system/dic/all', {}, data => {
        this.array = data
      })
    }
  }
}
</script>
<style lang="less" scoped>
</style>
